<#include "/common/easyui-css.html">
<#include "/common/easyui-js.html">
<#include "/common/loading.html">
<script type="text/javascript" src="/lib/layer/2.4/layer.js"></script>
<body class="easyui-layout">
<!-- 说明 字符串：Finance，作为替换字符串 -->
<div class="easyui-layout" style="width:100%;height:100%;">
    <!-- 主表  -->
    <table id="info_table" class="easyui-datagrid" title="" style="width:100%;height:100%;padding-bottom: 0px;"
           data-options="rownumbers:true, pagination:true,singleSelect:true,
					  method:'get',
					  url: '/info-list/1/20/'+${id},
					  toolbar:'#tb',
					  loadMsg : '数据加载中',
					  onAfterEdit:function(index,row){
						updateActions(row);
					 },
					 onLoadSuccess:function(data){
                        $('.delete').linkbutton({plain:true,iconCls:'icon-remove'});
                        $('.upload').linkbutton({plain:true,iconCls:'icon-upload'});
                         $('.uuid').linkbutton({plain:true,iconCls:'icon-new'});
                   },
					  showFooter: true" >
        <thead>
        <tr>
            <th data-options="field:'proID',width:40,align:'center',formatter:uuidfile"></th>
            <th data-options="field:'descValue',width:450,align:'center' ">相关信息</th>
            <th data-options="field:'state',width:200,align:'center'">时间</th>
            <th data-options="field:'id',width:100,align:'center' ,formatter:idFormatter ">操作</th>
        </tr>
        </thead>
    </table>
</div>

<!-- 搜索框 -->
<div id="tb" style="padding:5px;height:auto">
    <div>
        模板名称1:<input class="easyui-textbox" id="to" style="width:120px" >
        <a href="#" class="easyui-linkbutton" iconCls="icon-search" id="searchByParameter">搜索</a>
    </div>
    <div style="margin:5px 0;"></div>
    <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'" id="add">新增</a>
    <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-edit'" id="edit">修改</a>
    <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-download'"  id="export">导出</a>
</div>


<script>
    function idFormatter(value,row) {
        var button ='';
        button += '<a href="#" class="delete" title="删除" onclick=\'del('+value+')\'></a>';
        button += '<a href="#" class="upload" title="上传" onclick=\'upload_info('+row.proID+','+row.id+')\'></a>';
        return button;
    }
</script>

<!-- 按钮操作 -->
<script type="text/javascript">

    $('#add').click(function () {
        var id = ${id};
        var url = '/project-info-add/'+id;
        var index = parent.layer.open({
            title:'投后管理-相关信息新增',
            type: 2,
            area: ['950px', '650px'],
            fixed: true, //不固定
            maxmin: true,
            content: url,
            end: function(){
                $('#info_table').datagrid('reload');
            }
        });
    });
    // //编辑
    $('#edit').click(function () {
        var row = $('#info_table').datagrid('getSelected');
        if (row){
            var id = row.id;
            var url = '/project-info-edit/'+id;
            var index = parent.layer.open({
                title:'投后管理-相关信息修改',
                type: 2,
                area: ['950px', '650px'],
                fixed: true, //不固定
                maxmin: true,
                content: url,
                end: function(){
                    $('#info_table').datagrid('reload');
                }
            });
        } else{
            parent.layer.msg("请选择需要修改的相关信息")
        }
    });
    $('#save').click(function () {
        var row = $('#info_table').datagrid('getSelected');
        if (row){
            var index = $('#info_table').datagrid('getRowIndex', row);
        } else {
            index = 0;
        }
        $('#info_table').datagrid('endEdit',index);
    });

    function  del(val) {
        parent.layer.confirm('你确定要删除此相关信息？', {
            btn: ['删除','取消'] //按钮
        }, function(){
            $.ajax({
                url : '/info-ins-upd-del',
                data : {id:val,tm:new Date().getTime(),deleteflag:'Y'},
                async: false,
                type : 'post',
                success :function () {
                    $('#info_table').datagrid('reload');
                }
            })
            parent.layer.closeAll('dialog');
        }, function(){

        });
    }

    function upload_info(val,id) {
        var url = '/project-touhou-upload/'+val+'/th_zt_info_'+id;
        var index = parent.layer.open({
            title:'投后管理-相关信息上传',
            type: 2,
            area: ['700px', '450px'],
            fixed: true, //不固定
            maxmin: true,
            content: url,
            end:function () {
                var handler = '/info-list/1/20/'+${id};
                $('#info_table').datagrid('options').url = handler;
                $('#info_table').datagrid('reload');
            },
        });
    }

    function uuidfile(value,row){
        var result = '';
        $.ajax({
            url : '/project-touhou-has-file/'+value+'/th_zt_info_'+row.id,
            async : false,
            success :function (data) {
                result = data;
            }
        })
        var button = '';
        if(result){
            button += '<a href="#" class="uuid" title="文件已经上传" onclick="uidFile(\''+value+'\','+row.id+')"></a>';
        }
        return button;
    }
    function uidFile(value,id){
        var url = '/project-touhou-files-show/'+value+'/th_zt_info_'+id;
        var index = layer.open({
            title: false,
            type: 2,
            area: ['900px', '450px'],
            fixed: true, //不固定
            maxmin: true,
            content: url
        });
    }

</script>

<!-- 分页 -->
<script type="text/javascript">

    function updateActions(row){
        var url = '/info-ins-upd-del';
        $.ajax({
            url : url,
            data : {info:JSON.stringify(row),tm:new Date().getTime()},
            async : true,
            type : 'post',
            success :function () {
                $('#info_table').datagrid('reload');
            }
        })
    }

    $('#export').click(function(){
        window.location = "/info-download";
    });

    $(function(){
    	var p = $('#info_table').datagrid().datagrid('getPager');
    	p.pagination({
    		pageSize: 20, //每页显示的记录条数，默认为10
    		pageList: [20, 40, 60], //可以设置每页记录条数的列表
    		onSelectPage: function (pageNumber, pageSize) {
    		    if(pageNumber==0){
    		        pageNumber = 1;
               }
    			var handler = '/info-list/'+pageNumber+"/"+pageSize+"/"+${id};
    			$('#info_table').datagrid('options').url = handler;
    			$('#info_table').datagrid('reload');
    		}
    	});
    })
</script>